import { GameData } from "../game/GameData";
import { GameState } from "../game/GameState";
import { AnimalDatas } from "../game/GameDefine";
import { EventKey } from "../common/Key";
import { TaskMgr } from "../game/TaskMgr";
cc.Class({
    extends: require('BasePanel'),

    properties: {
        sprAnimal: cc.Sprite,
        labName: cc.Label,
    },
    onLoad() {
        this._super();
    },

    onEnter(args, action = true) {
        this._super(args, action);

        let data = AnimalDatas[args.index];
        let url = 'textures/animals/' + data.icon;
        G.common.setSpriteFrame(this.sprAnimal, url);

        this.labName.string = data.name;
        G.ad.show(G.ad.AD_BANNER);
    },

    onExit(args) {
        this._super(args);
        G.ad.hide(G.ad.AD_BANNER);
    },



    show() {
        this._super();

    },

    hide(cb) {
        this._super(cb);
    },
    onEnable() {

    },
    onDisable() {
    },

    buttonListener: function (button) {
        G.game.gameAudioMgr.playBtn();
        let name = button.node.name;
        if (name == 'btnClose') {
            this.onClose();
        } else if (name == 'btnShare') {
            G.partner.sendEvent('随机动物', { '类型': '随机动物' });
            G.ad.show(G.ad.AD_VIDEO, (param) => {
                if (param.event == G.ad.EVENT_SHOW_SUCC) {
                    G.partner.sendEvent('视频广告', { '类型': '随机动物' });
                    this.onClose();
                    G.onFire.fire(EventKey.EVENT_GEN_ANIMAL, { index: this.enterArgs.index });
                    G.utils.putPoolNode('nodePoolRandomAnimal', this.enterArgs.node);
                    TaskMgr.addDaliyTask(5, 1);
                } else {
                    G.partner.sendEvent('分享', { '类型': '随机动物' });
                    G.partner.share({ title: '瞧瞧这可怜的小家伙，跟我走吧' }, () => {
                        this.onClose();
                        G.onFire.fire(EventKey.EVENT_GEN_ANIMAL, { index: this.enterArgs.index });
                        G.utils.putPoolNode('nodePoolRandomAnimal', this.enterArgs.node);
                        TaskMgr.addDaliyTask(5, 1);
                    });
                }
            })
        } else if (name == 'btnDrive') {
            this.onClose();
            G.utils.putPoolNode('nodePoolRandomAnimal', this.enterArgs.node);
        }
    },

    onTouchStart() {

    },
});
